package net.janeluo.rs.module;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.janeluo.rs.bean.JsonReturnMessage;
import net.janeluo.rs.entity.RS_Menus;
import net.janeluo.rs.entity.RS_Shops;
import net.janeluo.rs.service.MenusManagerService;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

/**
 * 店铺菜单管理模块
 * 
 * @author DLK)JaneLuo
 * @version 1.0.0
 */
@IocBean
@At("/")
public class MenuManagerModule {
    private static final Log log = Logs.getLog(MenuManagerModule.class);
    
    @Inject
    private MenusManagerService menusManagerService;
    
    /**
     * 初始化显示菜单列表
     */
    @At("MenuManager")
    @Ok("jsp:views.MenuManager")
    public List<RS_Menus> initMenuManager(HttpServletRequest req, @Param("sid") Integer sid){
        log.debug("------------------- 菜单初始化显示开始 ------------------");
        
        List<RS_Menus> menusList = menusManagerService.getMenusList(sid, null);
        req.getSession().setAttribute("menuName", "ShopManager");
        req.setAttribute("sid", sid);
        
        log.debug("------------------- 菜单初始化显示结束 ------------------");
        return menusList;
    }
    
    /**
     * 添加店铺
     * 
     * @param shop
     */
    @At("AddMenu")
    @Ok("->:/MenuManager.nut")
    public void addMenu(@Param("..") RS_Menus entity){
        log.debug("----------- 添加菜单开始 ------------");
        
        menusManagerService.insertMenu(entity);
        
        log.debug("----------- 添加菜单结束 ------------");
    }


    /**
     * 删除菜单信息
     */
    @At("DeleteMenu")
    @Ok("->:/MenuManager.nut")
    public void deleteMenu(@Param("mids") Integer[] mids) {
        log.debug("--------------- 删除店铺信息开始 ----------------");
        
        menusManagerService.deleteMenus(mids);
        
        log.debug("--------------- 删除店铺信息结束 ----------------");
    }
    /**
     * 查询店铺列表
     * 
     * @return
     */
    @At("GetShopList")
    @Ok("json")
    public JsonReturnMessage getShops(){
        JsonReturnMessage mess = new JsonReturnMessage();
        List<RS_Shops> shop = menusManagerService.getShopList();
        if (shop != null) {
            mess.setSuccess("0");
            mess.setMessage(shop);
        } else {
            mess.setSuccess("1");
        }
        return mess;
    }
    
}
